package com.qf.factory;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class BeanFactorys {

    private static Map<String, Object> map = new HashMap();

    static {
        try {
            Properties properties = new Properties();

            InputStream is = BeanFactorys.class.getResourceAsStream("/config.ini");

            properties.load(is);

            Set<String> strings = properties.stringPropertyNames();

            for (String key : strings) {

                String property = properties.getProperty(key);

                Class aClass = Class.forName(property);

                Object instance = aClass.newInstance();

                map.put(key, instance);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static Object getBean(String key)
    {
        return map.get(key);
    }

    public static void main(String[] args)
    {
        Object servlet = getBean("Servlet");
        System.out.println(servlet);
    }
}